using System;
using System.Collections.Generic;
using System.Text;
using CMUSHrun.Server;
using System.Runtime.Serialization;
using System.Xml.Serialization;

/*
 * Don't serialize event handlers. The objects may not bind correctly
 */

namespace CMUSHrun.Objects
{

    /// <summary>
    /// A player object
    /// </summary>
    [Serializable,
    XmlRoot("GamePlayer")]
    public class MushPlayer : MushObject, ISerializable
    {
        /// <summary>
        /// Defines the event for the text to be raised to the player connection
        /// </summary>
        public event EventHandler<MushPlayerTextPostEventArgs> TextToObjectEvent;

        /// <summary>
        /// Constructor for a Mush player object
        /// </summary>
        public MushPlayer()
            : base()
        {
        }

        /// <summary>
        /// Process the text, sending it out to the connection
        /// </summary>
        /// <param name="source">The origin object providing the text</param>
        /// <param name="Text">The text provided</param>
        protected override void OnTextToObject(MushObject source, string Text)
        {
            base.OnTextToObject(source, Text);

            // Alert any listeners that we have information
            if (TextToObjectEvent != null)
            {
                TextToObjectEvent(this, new MushPlayerTextPostEventArgs(source, Text));
            }
        }


        #region ISerializable Members

        /// <summary>
        /// Public constructor for rebuilding a player object
        /// </summary>
        /// <param name="info"></param>
        /// <param name="context"></param>
        public MushPlayer(SerializationInfo info, StreamingContext context) : base(info, context) { }

        void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
        {
            base.GetObjectData(info, context);
        }

        #endregion
    }


    public class MushPlayerTextPostEventArgs : EventArgs
    {
        /// <summary>
        /// The source of the message to post
        /// </summary>
        public MushObject Source;

        /// <summary>
        /// The message to post
        /// </summary>
        public String Text;

        public MushPlayerTextPostEventArgs(MushObject source, string text)
        {
            Source = source;
            Text = text;
        }
    }
}
